﻿#include "localcontext.h"

#include <QDebug>

LocalContext* LocalContext::m_instance = nullptr;
QMutex LocalContext::m_instanceMutex;

LocalContext::LocalContext(QObject *parent) : QObject(parent)
{
    // 初始化
}

LocalContext::~LocalContext()
{
}

LocalContext *LocalContext::instance()
{
    // 双重锁定，减少每次开销，只有 if (m_instance == nullptr) 才需要锁定，极低概率
    if (m_instance == nullptr) {
        // 线程安全
        m_instanceMutex.lock();
        if(m_instance == nullptr)
            m_instance = new LocalContext();
        m_instanceMutex.unlock();
    }

    return m_instance;
}























